﻿using System;
using System.Xml;

namespace QDT.Payment.AllInPay.Api
{
    /// <summary>
    /// 交易请求报文中记录明细类
    /// </summary>
    public class SingleTradeRequest :  Request
    {
        SingleTradePackage single;
          /// <summary>
        /// 初始化交易请求报文
        /// </summary>
        /// <param name="trxCode"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="reqSn"></param>
        /// <param name="level"></param>
        /// <param name="businessCode"></param>
        /// <param name="merchantId"></param>
        public SingleTradeRequest(SingleTradePackage single,string trxCode, string userName, string password, string reqSn, int level, string businessCode, string merchantId)
            : base(trxCode, "03", 2, userName, password, reqSn,"TRANS")
        {
            m_elInfo.AppendChild(CreateValueElement("LEVEL", level.ToString()));
            XmlElement trxEl = m_elBody;
            trxEl.AppendChild(CreateValueElement("BUSINESS_CODE", businessCode));
            trxEl.AppendChild(CreateValueElement("MERCHANT_ID", merchantId));
            trxEl.AppendChild(CreateValueElement("SUBMIT_TIME", DateTime.Now.ToString("yyyyMMddHHmmss")));
            trxEl.AppendChild(CreateValueElement("E_USER_CODE", merchantId));
            trxEl.AppendChild(CreateValueElement("VALIDATE", ""));
            trxEl.AppendChild(CreateValueElement("CVV2", ""));
            trxEl.AppendChild(CreateValueElement("BANK_CODE", single.BankCode));
            trxEl.AppendChild(CreateValueElement("ACCOUNT_TYPE", "00"));
            trxEl.AppendChild(CreateValueElement("ACCOUNT_NO", single.AccountNo));
            trxEl.AppendChild(CreateValueElement("ACCOUNT_NAME", single.AccountName));
            trxEl.AppendChild(CreateValueElement("ACCOUNT_PROP", "0"));
            trxEl.AppendChild(CreateValueElement("AMOUNT", single.Amount.ToString()));
            trxEl.AppendChild(CreateValueElement("CURRENCY","CNY"));
            trxEl.AppendChild(CreateValueElement("ID_TYPE", "0"));
            trxEl.AppendChild(CreateValueElement("ID", single.ID));
            trxEl.AppendChild(CreateValueElement("SETTACCT", ""));
            trxEl.AppendChild(CreateValueElement("TEL", single.Tel));
            trxEl.AppendChild(CreateValueElement("CUST_USERID", single.CustUserID));
            trxEl.AppendChild(CreateValueElement("SETTGROUPFLAG", ""));
            trxEl.AppendChild(CreateValueElement("SUMMARY", ""));
            trxEl.AppendChild(CreateValueElement("REMARK", single.Remark));
           // m_elBody.AppendChild(trxEl);
            //m_package.AppendChild(trxEl);
            
        }
        public void addSingles(SingleTradePackage single)
        {
            this.single = single;
        }
    }
}
